/*
Copyright (C) 2021-2025 Casa Xu (also Zhiyan Xu) from HIT

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*
 * LOS_MEMS.h
 *
 *  Created on: 2023年3月27日
 *      Author: 64435
 */

#ifndef PERIPHERAL_LAYER_INC_LOS_MEMS_H_
#define PERIPHERAL_LAYER_INC_LOS_MEMS_H_

#include "LOS_SYS.h"

typedef struct LOS_MEMSSTA_t
{
    uint8_t VAL;    //数据有效性标志，0：有效， 其他值：无效
    uint8_t CMD;    //开关机指令状态,发送开机指令后置1，发送关机指令后置0
    uint8_t PWR;    //电源状态，读取电源遥测，通电为1，断电为0
    uint8_t MSG;    //通信状态，通信正常为0，通信异常为其他值
    uint8_t RBCNT;  //复位次数
    uint8_t NFR;    //Need For Reset 需要复位标志位，1为需要复位，0为不需要
    uint8_t RBT_F;              //表示单机是否处于重启过程中 0：未处于 1：处于重启过程中
    uint8_t RECOV;               //恢复计数：单机重启完成后，需要等待一段时间才能再次进入重启流程，将该计数置于某一值开始倒计时，倒计时结束后会再次开始判断是否需要重启
    uint16_t FlagF_CNT;         //物理量异常重启计数
    uint16_t FlagT_CNT;         //通信异常重启计数
    uint16_t FlagY_CNT;    
    uint32_t TMCNT;
    float gyro_x;
    float gyro_y;
    float gyro_z;
    float acc_x;
    float acc_y;
    float acc_z;
    uint16_t DIAG_STAT;
    uint16_t odata[6];  //原始数据依次为XYZ角速度 XYZ角加速度
    

}LOS_MEMSSTA_t;

typedef struct LOS_MEMSTEST_t
{
    uint8_t axis_velsel;  //角速度上注轴选择  0:不改变/恢复  1:X轴  2:Y轴  3:Z轴  4:开始作用
    float x_gyro_upt;     //X轴角速度上注值（用于地面测试故障）
    float y_gyro_upt;     //Y轴角速度上注值（用于地面测试故障）
    float z_gyro_upt;     //Z轴角速度上注值（用于地面测试故障）
}LOS_MEMSTEST_t;

LOS_MEMSSTA_t STA_MEMS;
LOS_MEMSTEST_t TEST_MEMS;

void LOS_MEMS_GetStaDyn();
void LOS_CAN_MEMSCallBackDyn(LOS_CANMSG_t* can_re);
void LOS_MEMS_GetGyro();
void LOS_MEMS_BurstRead();
void LOS_MEMS_Getgyrox();
void LOS_MEMS_Getgyroy();
void LOS_MEMS_Getgyroz();
void LOS_MEMS_Getaccx();
void LOS_MEMS_Getaccy();
void LOS_MEMS_Getaccz();
void LOS_MEMS_PWROn();
void LOS_MEMS_PWROff();

#endif /* PERIPHERAL_LAYER_INC_LOS_MEMS_H_ */
